package com.hsr.web.utils;

import com.hsr.web.enums.ResultCode;
import com.hsr.web.vo.ResultVO;
import org.springframework.http.MediaType;
import org.springframework.http.MediaTypeFactory;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;

import java.util.Optional;

public class ResultVOUtil {
    public static ResultVO success(Object object) {
        ResultVO resultVO = new ResultVO();
        resultVO.setData(object);
        resultVO.setCode(0);
        resultVO.setMsg("成功");
        resultVO.setSuccess(true);
        return resultVO;
    }

    public static ResultVO success() {
        return success(null);
    }

    public static ResultVO error(ResultCode resultCode) {
        ResultVO resultVO = new ResultVO();
        resultVO.setCode(resultCode.getCode());
        resultVO.setMsg(resultCode.getMessage());
        resultVO.setSuccess(false);
        return resultVO;
    }


    public static void main(String[] args) {
        String[] fileNames = new String[]{"file/test.PNG", "测试.pdf", "视频.mp4"};
        for (String fileName : fileNames) {
            Optional<MediaType> mediaType = MediaTypeFactory.getMediaType(fileName);
            System.out.println(mediaType.orElse(MediaType.APPLICATION_OCTET_STREAM).toString());
        }
    }
}
